<script setup lang="ts">
import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html.vue'
import { fetchTextAPI } from '@/apis/fetchText'

const content = ref('')

onLoad(async (options) => {
  if (options && options.keyword) {
    // 根据传入的 keyword 设置页面标题
    if (options.keyword === 'fwxy')
      uni.setNavigationBarTitle({ title: '服务协议' })
    else
      uni.setNavigationBarTitle({ title: '隐私政策' })

    // 请求文本内容
    const res = await fetchTextAPI(options.keyword)
    if (res.data?.code === 1)
      content.value = res.data?.data.content || ''
    else
      uni.showToast({ title: res.data?.msg, icon: 'none' })
  }
  else {
    uni.showToast({ title: '获取失败', icon: 'none' })
  }
})
</script>

<template>
  <mp-html
    :content="content"
    container-style="padding: 30rpx; min-height: 100vh; background-color: #FFFFFF;"
  />
</template>

<route lang="yaml">
name: 'protocol'
layout: 'custom'
</route>
